package com.grass.cropTradingCenter.controller.shop;


import com.grass.cropTradingCenter.common.Result;
import com.grass.cropTradingCenter.common.annotation.LoginFree;
import com.grass.cropTradingCenter.pojo.dto.shop.RealAuthStateDto;
import com.grass.cropTradingCenter.pojo.dto.shop.ShopHomeData;
import com.grass.cropTradingCenter.pojo.dto.shop.ShopUser;
import com.grass.cropTradingCenter.pojo.entity.MiniShopUser;
import com.grass.cropTradingCenter.pojo.entity.ShopAuth;
import com.grass.cropTradingCenter.pojo.vo.shop.ShopAuthVo;
import com.grass.cropTradingCenter.pojo.vo.user.LoginVo;
import com.grass.cropTradingCenter.pojo.vo.user.RegisterVo;
import com.grass.cropTradingCenter.pojo.vo.user.SendUserLoginVo;
import com.grass.cropTradingCenter.service.MiniShopUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/shop/user")
@Api(tags = "商家用户接口")
public class ShopUserController {

    @Autowired
    MiniShopUserService miniShopUserService;


    @LoginFree
    @PostMapping("/sendEmail/login")
    @ApiOperation("登录或找回密码邮箱验证码")
    public Result sendEmailLogin(@RequestBody SendUserLoginVo vo){
        miniShopUserService.sendEmailLogin(vo);
        return Result.success();
    }

    @LoginFree
    @PostMapping("/sendEmail/register")
    @ApiOperation("注册邮箱验证码")
    public Result sendEmailRegister(@RequestBody SendUserLoginVo vo){
        miniShopUserService.sendEmailRegister(vo);
        return Result.success();
    }

    @LoginFree
    @PostMapping("/login")
    @ApiOperation("登录")
    public Result<String> login(@RequestBody LoginVo vo){
        return Result.success(miniShopUserService.login(vo));
    }

    @LoginFree
    @PostMapping("/register")
    @ApiOperation("注册")
    public Result<String> register(@RequestBody @Validated RegisterVo vo) throws InterruptedException {
        return Result.success(miniShopUserService.register(vo));
    }

    @LoginFree
    @PostMapping("/find/password")
    @ApiOperation("找回密码")
    public Result<String> findPassword(@RequestBody @Validated RegisterVo vo) throws InterruptedException {
        return Result.success(miniShopUserService.findPassword(vo));
    }

    @GetMapping("/userInfo")
    @ApiOperation("获取个人信息")
    public Result<ShopUser> getUserInfo()  {
        return Result.success(miniShopUserService.getUserInfo());
    }

    @PostMapping("/realAuth")
    @ApiOperation("实名认证")
    public Result realAuth(@RequestBody ShopAuthVo vo) {
        miniShopUserService.realAuth(vo);
        return Result.success();
    }

    @GetMapping("/getRealAuth")
    @ApiOperation("获取实名认证信息")
    public Result<ShopAuth> realAuth() {
        return Result.success(miniShopUserService.getRealAuth());
    }

    @GetMapping("/realAuth/state")
    @ApiOperation("实名认证状态")
    public Result<RealAuthStateDto> realAuthState() {
        return Result.success(miniShopUserService.realAuthState());
    }


    @GetMapping("/homeData")
    @ApiOperation("大屏信息")
    public Result<ShopHomeData> homeData() {
        return Result.success(miniShopUserService.homeData());
    }

    @GetMapping("/userDetail")
    @ApiOperation("用户详情")
    public Result<MiniShopUser> userDetail() {
        return Result.success(miniShopUserService.userDetail());
    }

    @PostMapping("/updateShopUser")
    @ApiOperation("更新个人信息")
    public Result updateShopUser(@RequestBody MiniShopUser vo) {
        miniShopUserService.updateShopUser(vo);
        return Result.success();
    }

}
